/******************************************************************************
 * Copyright (C) 2024 EternalChip, Inc.(Gmbh) or its affiliates.
 *
 * All Rights Reserved.
 *
 * @file bsp_AHT21_driver.h
 *
 * @author Emond
 *
 * @brief 
 *
 * Processing flow:
 *
 * call directly.
 *
 * @version V1.0
 *
 * @note 1 tab == 4 spaces!
 *
 *****************************************************************************/
#ifndef __BSP_AHT21_DRIVER_H__
#define __BSP_AHT21_DRIVER_H__

#include "bsp_AHT21_reg.h"
#include <stdint.h>
#include <stdio.h>

#define OS_SUPPORTING
#define DEBUG

typedef enum
{
    AHT21_OK                = 0,
    AHT21_ERRO              = 1,
    AHT21_ERROTIMEOUT       = 2,
    AHT21_ERRORESOUCE       = 3,
    AHT21_ERROPARAMETER     = 4,
    AHT21_ERRONOMEMORY      = 5,
    AHT21_ERROISR           = 6,
    AHT21_RESERD            = 0X7FFFFFFF
} aht21_status_t;

typedef struct
{
    aht21_status_t (*pf_iic_init)(void *);
    aht21_status_t (*pf_iic_deinit)(void *);

    aht21_status_t (*pf_iic_start)(void *);
    aht21_status_t (*pf_iic_stop)(void *);
    aht21_status_t (*pf_iic_send_ack)(void *);
    aht21_status_t (*pf_iic_send_noack)(void *);
    aht21_status_t (*pf_iic_wait_ack)(void *);
    aht21_status_t (*pf_iic_send_bytes)(uint8_t ADDR, uint8_t *pdata,uint8_t datalength);
    aht21_status_t (*pf_iic_receive_bytes)(uint8_t ADDR, uint8_t *pdata,uint8_t datalength);

    aht21_status_t (*pf_iic_critical_enter)(void *);
    aht21_status_t (*pf_iic_critical_exit)(void *);
}aht21_iic_interface_t;

typedef struct
{
    aht21_status_t (*pf_get_tick_count)(void *);
}aht21_time_base_interface_t;

#ifdef OS_SUPPORTING
typedef struct
{
    aht21_status_t (*pf_yelid)(void *);
}aht21_yelid_interface_t;
#endif

typedef struct
{
    aht21_status_t (*pf_lock)(void *);
    aht21_status_t (*pf_unlock)(void *);

    aht21_status_t (*pf_disable_irq)(void *);
    aht21_status_t (*pf_enable_irq)(void *);
}aht21_irq_interface_t;

typedef struct aht21_driver_t
{
    aht21_iic_interface_t *p_iic_instance;
    aht21_time_base_interface_t *p_timebase_instance;
    aht21_yelid_interface_t *p_aht21_yelid_instance;
    aht21_irq_interface_t *p_aht21_irq_instance;

    int8_t (*pfinst)(struct aht21_driver_t *aht21_instance, aht21_iic_interface_t *p_iic_instance, aht21_time_base_interface_t *p_timebase_instance,
#ifdef OS_SUPPORTING
                     aht21_yelid_interface_t *p_aht21_yelid_instance, 
#endif
                     aht21_irq_interface_t *p_aht21_irq_instance);

    int8_t (*pfdeinst)(struct aht21_driver_t *aht21_instance);
    int8_t (*pfinit)(struct aht21_driver_t *aht21_instance);
    int8_t (*pfdeinit)(struct aht21_driver_t *aht21_instance);
    int8_t (*pfread_id)(struct aht21_driver_t *aht21_instance);
    int8_t (*pfread_temp_humi)(struct aht21_driver_t *aht21_instance,float *temp,float *humi);
    int8_t (*pfread_humi)(struct aht21_driver_t *aht21_instance,float *humi);
    int8_t (*pfhibernating)(struct aht21_driver_t *aht21_instance);
    int8_t (*pfwake_up)(struct aht21_driver_t *aht21_instance);
    int8_t (*pfsleep)(struct aht21_driver_t *aht21_instance);
}bsp_aht21_driver_t;

aht21_status_t (*pfinst)(struct aht21_driver_t *aht21_instance, aht21_iic_interface_t *p_iic_instance, aht21_time_base_interface_t *p_timebase_instance,
#ifdef OS_SUPPORTING
    aht21_yelid_interface_t *p_aht21_yelid_instance, 
#endif
    aht21_irq_interface_t *p_aht21_irq_instance);

#endif
